package cac.fenjian.resource.msfactroy.api;

import cac.fenjian.resource.MsFactory.dto.MsFactoryDTO;
import com.cac.dme.adapter.rest.client.RestClient;
import com.cac.dme.adapter.rest.msg.QueryReqBean;
import com.cac.dme.adapter.rest.msg.ResponseMsg;
import com.cac.dme.adapter.utils.RestClientUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @program test-curd
 * @description 专业厂配置信息接口API
 * @author: LSL
 * @create: 2022-07-15-14-35
 **/
@RestController
@RequestMapping("/MsFactoryApi")
public class MsFactoryApi {

    /**
     * 服务编码
     */
    private static final String SERVICE_CODE ="xdCommonData";
    private static final String BATH_PATH = "/MsFactory/";

    @Autowired
    private RestClient restClient;

    /**
     * 新增接口
     * @param msFactoryDTO
     * @return
     */
    @PostMapping("/insertFactory")
    public String insertMsFactoryDTO(@RequestBody MsFactoryDTO msFactoryDTO){
        String url = BATH_PATH + "/save/v1";
        ResponseMsg<String> responseMsg = restClient.doPost(SERVICE_CODE, url, msFactoryDTO, new ParameterizedTypeReference<ResponseMsg<String>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }

    /**
     * 批量新增
     * @param msFactoryDTOS
     * @return
     */
    @PostMapping("/insertBatchMsFactory")
    public Integer insertBatchMsFactoryDTO(@RequestBody List<MsFactoryDTO> msFactoryDTOS){
        String url = BATH_PATH+"saveBatch/v1";
        ResponseMsg<Integer> responseMsg = restClient.doPost(SERVICE_CODE, url, msFactoryDTOS, new ParameterizedTypeReference<ResponseMsg<Integer>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }

    /**
     * 根据条件查询数据
     * @param queryReqBean
     * @return
     */
    @PostMapping("/searchByParams")
    public List<MsFactoryDTO> searchByParams(@RequestBody QueryReqBean<MsFactoryDTO> queryReqBean){
        String url = BATH_PATH+"searchByParams/v1";
        ResponseMsg<List<MsFactoryDTO>> responseMsg = restClient.doPost(SERVICE_CODE, url, queryReqBean, new ParameterizedTypeReference<ResponseMsg<List<MsFactoryDTO>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }

    /**
     * 修改数据
     * @param msFactoryDTO
     * @return
     */
    @PostMapping("/updateMsFactoryDTO")
    public Integer updateMsFactoryDTO(@RequestBody MsFactoryDTO msFactoryDTO){
        String url = BATH_PATH + "updateDate/v1";
        ResponseMsg<Integer> responseMsg = restClient.doPost(SERVICE_CODE, url, msFactoryDTO, new ParameterizedTypeReference<ResponseMsg<Integer>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }

    /**
     * 删除数据
     * @param id
     * @return
     */
    @PostMapping("/deleteDate")
    public Integer deleteDate(@RequestBody String id ){
        String url = BATH_PATH + "deleteDate/v1";
        ResponseMsg<Integer> responseMsg = restClient.doPost(SERVICE_CODE, url, id, new ParameterizedTypeReference<ResponseMsg<Integer>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }

}
